extends Node


func _ready() -> void:
	if get_tree().paused:
		get_tree().paused = false
	
	VN_SystemUI.show_hud() #显示HUD
	
	if VN_SystemUI.pending_load_slot != "":
		print("检测到跨场景读档请求...")
		
		await get_tree().process_frame
		
		Dialogic.Save.load(VN_SystemUI.pending_load_slot)
		VN_SystemUI.pending_load_slot = ""
		
		#读档后，立刻刷新一次按钮状态
		VN_SystemUI.update_drink_menu_visibility()
		
	else:
		#正常开局
		print("正常开局")
		
		#强制把酒单功能锁上
		Dialogic.VAR.set_variable("HUD.drink_menu_unlocked", false)
		
		#根据刚刚锁上的状态，强制刷新UI
		VN_SystemUI.update_drink_menu_visibility()
		Dialogic.start("character2_2")


		
	
	Dialogic.signal_event.connect(_on_dialogic_signal)
	
	
func _on_dialogic_signal(arg: String):
	var clean_arg = arg.strip_edges()
	
	print("收到信号: |" + clean_arg + "|")
	
	if arg == "start_chapter_2_bar":
		print("检测到开始游戏信号，启动黑屏转场...")
		SceneLoader.change_scene_with_grid_spread("res://scene/chapter_2_bar_1.tscn")
		VN_SystemUI.hide_hud()
		VN_SystemUI.btn_handle.visible = false
	if arg == "start_bar2":
		print("检测到开始游戏信号，启动黑屏转场...")
		SceneLoader.change_scene_with_grid_spread("res://scene/chapter_2_bar_2.tscn")
		VN_SystemUI.hide_hud()
		VN_SystemUI.btn_handle.visible = false
	if arg == "start_bar3":
		print("检测到开始游戏信号，启动黑屏转场...")
		SceneLoader.change_scene_with_grid_spread("res://scene/chapter_2_bar_3.tscn")
		VN_SystemUI.hide_hud()
		VN_SystemUI.btn_handle.visible = false
